package com.bcsq.todolistdemo.demo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.bcsq.todolistdemo.R;
import com.bcsq.todolistdemo.demo.adapter.IconAdapter;


public class IconChooseActivity extends AppCompatActivity {
    Toolbar toolbar;
    Context mContext;
    ListView lvIcons;

    Pair<Integer, String> [] data = new Pair[]{
            new Pair<>(R.drawable.hint, "hint"),
            new Pair<>(R.drawable.light_gray, "light_gray"),
            new Pair<>(R.drawable.light_green, "light_green"),
            new Pair<>( R.drawable.save, "save"),
            new Pair<>(R.drawable.success, "success"),
            new Pair<>(R.drawable.thermo_op_select_gray, "thermo_op_select_gray")
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_icon_choose);
        init();
//        CameraManager
    }

    private void init() {
        mContext = this;
        toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle("选择icon");

        lvIcons = findViewById(R.id.lv_icons);
        //为listview添加一个适配器
        lvIcons.setAdapter(new IconAdapter(mContext, data));

        //给列表item添加点击事件
        lvIcons.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent();
                //数据传递
                intent.putExtra("chooseIconId", data[i].first);
                //设置点击后的结果，改结果在protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) 函数中可以获取
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}
